#########################
#   Author : Leon yu    #
#   Date : 2025/06/12   #
#   Id : SM2772         #
#########################
from apiRespsAnalyze import *
from dbResps import dc
from datetime import datetime

# 数据解析
def queryEmployPerformanceReport(startTime, endTime):
    result = dict()
    result['employDetail'] = list()
    queryEmployDetailReport = analyzeQueryEmployPerformanceReport(startTime=startTime, endTime=endTime)
    
    if queryEmployDetailReport['total'] != 0:
        for item in queryEmployDetailReport['list']:
            employDetail = dict()
            reportDay = datetime.strptime(dc.timestamp2Data(item['reportDay']), "%Y/%m/%d %H:%M:%S").strftime('%Y-%m-%d')
            employ= f"{item['employeeName']}_{item['employeeId']}_{reportDay}"
            employDetail[employ] = {
                "orderAmount":item["orderAmount"]["amount"],
                "tipAmount":item["tipAmount"]["amount"],
                "discountAmount":abs(item["discountAmount"]["amount"]),
                "actualAmount":item["actualAmount"]["amount"]
            }
            result['employDetail'].append(employDetail)

    return result

# startTime = 1718557200000
# endTime = 1718729999000
# result = queryEmployPerformanceReport(startTime, endTime)
# print(result)